package com.musiclibrary.dao;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import com.musiclibrary.persistence.MusicCategory;

public class MusicCategoryDaoImpl implements IMusicCategoryDao{

	private HibernateTemplate hibernateTemplate;
	
	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	@SuppressWarnings("unchecked")
	public List<MusicCategory> loadAll() {
		List<MusicCategory> musicCategories=null;
		try{
			musicCategories= getHibernateTemplate().loadAll(MusicCategory.class);
//			getHibernateTemplate().initialize(musicCategories);
		}catch(Exception e){
			e.printStackTrace();
		}
	return musicCategories;
	}
	
	public void persist(MusicCategory musicCategory){
		try{
			getHibernateTemplate().persist(musicCategory);
//			getHibernateTemplate().save(musicCategory);
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}
